package org.team4.service.meta;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.team4.constants.SQLConstant;
import org.team4.constants.StringConstant;
import org.team4.dao.DAOFactory;
import org.team4.dao.meta.ModuleDAO;
import org.team4.domain.VmetaModule;
import org.team4.exception.CRUDException;
import org.team4.service.IService;


@Service
public class ModuleService implements IService {

    private ModuleDAO moduleDAO;

    @Autowired
    public void setSessionFactory(SessionFactory sessionFactory) {
        moduleDAO = (ModuleDAO) DAOFactory.getDAO(sessionFactory, ModuleDAO.class);
    }

    /**
     * 根据父级ID查找模块
     * 
     * @param superId
     * @return
     * @throws CRUDException
     */
    public List<VmetaModule> findModuleBySuperId(String superId) throws CRUDException {
        return moduleDAO.find(SQLConstant.MODULE_BY_SUPERID_HQL, superId);
    }

    /**
     * 查找二级模块
     * 
     * @return
     * @throws CRUDException
     */
    public List<VmetaModule> findChildModule() throws CRUDException {
        return moduleDAO.find(SQLConstant.MODULE_CHILD_HQL, StringConstant.ROOT_ID);
    }

    /**
     * 查询全部
     * 
     * @return
     * @throws CRUDException
     */
    public List<VmetaModule> findAllModule() throws CRUDException {
        return moduleDAO.find(SQLConstant.MODULE_ALL_HQL);
    }

    /**
     * 根据ID查找模块
     * 
     * @param id
     * @return
     * @throws CRUDException
     */
    public VmetaModule findModuleById(String id) throws CRUDException {
        return moduleDAO.get(id);
    }
}